import Image

img = Image.open("04_edge.jpg")

if img.mode != 'L': 
    img = img.convert('L')
pixels = list(img.getdata())
w, h = img.size
l = []
outimg = Image.new('L', (w, h))
f = open('out.txt', 'w')
counter = 0
print w, h
for i in pixels:
    f.write(str(i) + '\t')
    if counter == int(w):
        f.write(str(i) + '\n')
        counter = 0
    counter += 1
#    if i < 118:
#        i = 0
#    
#    l.append(i)


#outimg.putdata(l)
#
#outimg.save('test.jpg')
